# 2.15 文件
fobj = open('user.txt', 'r')
for line in fobj:
    print(line)
fobj.close()

print(str(type(fobj)))

fobj = open('user.txt', 'r')
line = True
while line:
    line = fobj.readline()
    print(line)
fobj.close()

# 2.16 错误和异常
try:
    fobj = open('users.txt', 'r')
except IOError as e:
    print('file open error', e)


# 通过使用raise抛出异常

# 2.17 函数
def addMe2Me(x):
    'apply + operation to argument'
    return x + x


print(addMe2Me(13))


# 默认参数
def foo(debug=True):
    'determine if in debug mode with default argument'
    if debug:
        print('in debug mode')
    print('done')
foo()
